package org.wattdepot.cli.processor;

import java.util.List;
import org.wattdepot.cli.command.WattTotalGenerated;

/**
 * Parses the total command.
 * 
 * @author Kendyll Doi
 * @author Kimberly Heu
 *
 */
public class TotalCommand extends CommandLineInterface implements WattDepotCliCommand {
  
  /**
   * Parses the total command.
   * 
   * @param args The list of the user's arguments
   * @return The string containing the output from the command.
   */
  public String doCommand(List<String> args) {
    StringBuffer buf = new StringBuffer(200);
    String output = "";
    
    //total [carbon|energy] generated {source} day {day} sampling-interval {minutes}
    
    // Check the total number of arguments
    if (args.size() == 8) {
      // Check the syntax of the commands
      if (args.get(2).equalsIgnoreCase("generated") && args.get(4).equalsIgnoreCase("day") 
          && args.get(6).equalsIgnoreCase("sampling-interval")) {
        // Format of command is correct, so pass the information on to the method
        buf.append(WattTotalGenerated.totalGenerated(
            args.get(1), args.get(3), args.get(5), args.get(7), client));
        }
      else {
        // Incorrect syntax
        buf.append("Incorrect syntax for total command");
      }
    }
    else {
      // Incorrect number of arguments
      buf.append("Incorrect number of arguments for total command");
    }
    
    // Transfer the output to the string to be returned, and return
    output = buf.toString();
    return output;
  }
}
